package com.yxy.controller.admin;

import com.yxy.common.PageResult;
import com.yxy.common.Result;
import com.yxy.constant.RequestMapperConstant;
import com.yxy.domain.dto.BannerDTO;
import com.yxy.domain.dto.BannerPageQueryDTO;
import com.yxy.domain.vo.BannerPageQueryVO;
import com.yxy.service.BannerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(RequestMapperConstant.ADMIN_REQUEST_MAPPER + "banner")
@Slf4j
public class BannerController {

    private final BannerService bannerService;
    public BannerController(BannerService bannerService) {
        this.bannerService = bannerService;
    }

    /**
     * 添加banner
     * @param bannerDTO
     * @return
     */
    @PostMapping
    public Result add(@RequestBody BannerDTO bannerDTO){
        log.info("添加banner：{}", bannerDTO);
        bannerService.add(bannerDTO);
        return Result.success("添加成功");
    }

    /**
     * 获取banner列表
     * @param bannerPageQueryDTO
     * @return
     */
    @GetMapping
    public Result<PageResult> list(BannerPageQueryDTO bannerPageQueryDTO){
        log.info("获取banner列表");
        PageResult pageResult = bannerService.page(bannerPageQueryDTO);
        return Result.success("", pageResult);
    }

    /**
     * 删除banner
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable int id, String url){
        log.info("删除banner：{}", id, url);
        bannerService.delete(id, url);
        return Result.success("删除成功");
    }

    /**
     * 修改banner状态
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/{status}")
    public Result updateStatus(@PathVariable int id, @PathVariable int status){
        log.info("修改banner状态");
        bannerService.updateStatus(id, status);
        return Result.success("状态已更新");
    }
}
